package com.ganzalang.gmall.dubboconsumerservice.service.impl;

import com.ganzalang.gmall.dubboconsumerapi.dto.UserDTO;
import com.ganzalang.gmall.dubboconsumerservice.service.UserService;
import com.ganzalang.gmall.dubboproviderapi.rpc.user.UserRpcService;
import com.ganzalang.gmall.dubboproviderapi.rpc.user.model.UserResult;
import com.ganzalang.gmall.dubboproviderapi.rpc.user.param.UserRpcParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;

/**
 * @author Ganzalang
 * @description
 * @Date 2021/8/2 22:50
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @DubboReference(version = UserRpcService.VERSION, timeout = 3000)
    private UserRpcService userRpcService;

    /**
     * 根据名称获取用户信息
     *
     * @param name 用户姓名
     * @return 用户DTO
     */
    @Override
    public UserDTO getUserInfo(String name) {
        UserRpcParam param = new UserRpcParam();
        param.setName(name);
        UserResult userRes = userRpcService.getUserInfo(param);
        log.info("消费者调用服务UserRpcService服务，返回值为：{}", userRes);
        UserDTO userDTO = new UserDTO();
        userDTO.setName(userRes.getName());
        userDTO.setSex(userRes.getSex());
        userDTO.setId(userRes.getId());
        return userDTO;
    }
}
